﻿ @model ViewModels.BoardVM.BoardListVM

@{
    ViewBag.Title = "Hinoky.com :::: 게시물 목록보기";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style type="text/css">
    .searchtag {
        padding-left: 10px;
        font-size: 13px;
    }

    .writedate {
        padding-left: 10px;
        font-size: 13px;
        color:#999
    }

    .highlight {
        background-color: #FFFF00;
    }

</style>
<script src="/Scripts/jquery.highlight.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var searchtext = unescape(getQueryVariable("searchtext", ""));
        $("#txtSearchText").val(searchtext);

        // 검색된 KEYWORD 하이라이트
        $('.table-hover').highlight(searchtext);

        // 검색
        $("#txtSearchText").on("keydown", function (e) {
            var code = e.keyCode || e.which;
            if (code == 13) search();
        });

        // 검색
        $("#btnSearch").on("click", function () {
            search();
        });

        // 검색
        function search() {
            location.href = "/board/list?category=" + getQueryVariable("category", "*") + "&searchtext=" + escape(htmlEscape($("#txtSearchText").val())) + "&pageSize=" + @Model.SearchData.PageSize + "&page=" + @Model.SearchData.PageIndex + "";            
        }
    });
</script>

@{
    bool isAdmin = WebLib.AuthorizeService.MemberInfo.Instance.IsSignIn && WebLib.AuthorizeService.MemberInfo.Instance.UserRole.Contains("ADMIN");
}

<div class="bs-callout bs-callout-article">
    <h3>Article</h3>
    <p>주절 주절 게시판 입니다.</p>
</div>

<!-- (s) Search Areas -->
<div class="row">
    <div class="col-lg-9"></div>
    <div class="text-right col-lg-3">
        <div class="input-group input-group-sm">
            <input type="text" id="txtSearchText" class="form-control" placeholder="Search...">
            <span id="btnSearch" class="input-group-addon" style="cursor:pointer" >
                <span class="glyphicon glyphicon-search"></span>
            </span>
        </div>
    </div>
</div>

<div class="text-center"> 
    @foreach (var board in Model.BoardList)
    {
        <div class="row text-left" style="padding-top:10px">
            <table class="table-hover" style="width:98%;">
                <tr>
                    <td class="col-md-9">
                        <p class="text-primary">
                            <a href="@Html.Raw("/board/details/" + board.Idx + "?page=" + Model.SearchData.PageIndex + Model.SearchData.Parameters)">@board.Title</a> &nbsp;
                        </p>
                        <div class="small" style="line-height:24px; max-height:150px; overflow:hidden" ><p>@board.Body</p></div>
                        @if (!string.IsNullOrEmpty(board.SearchTag))
                        {
                            <br />
                            <span class="glyphicon glyphicon-tags" ><span class="searchtag">@board.SearchTag</span></span>
                        }
                        <br />
                        <span class="glyphicon glyphicon-time" ><span class="writedate">@board.WriteDate</span><span class="writedate">@Html.Raw("- Writen by " + board.WriteUserName + "(" + board.WriteUserId + ")")</span></span>
                    </td>
                    <td class="col-md-3 text-right">
                        @if (!string.IsNullOrEmpty(board.TitleImageUrl))
                        {
                            <img src="@board.TitleImageUrl" title="@board.Title" style="width:150px" />
                        }
                    </td>
                </tr>
            </table>
            <hr />
        </div>
    }

    @if (Model.BoardList.Count == 0)
    {
        <div class="listitem" >
            <table style="width:100%" >
                <tr>
                    <td style="vertical-align:top; text-align:center">
                        <h3>게시물이 존재하지 않습니다. <br /><br /><a href="/board/list">전체보기</a></h3>
                    </td>
                </tr>
            </table>
        </div>
    }
    
    <div class="col-md-4" >

    </div>
    <div class="col-md-4">
    @if (Model.BoardList.Count != 0)
    {
        @Html.Partial("_PagingControl", new WebLib.PagingVM() {CurrentPage = Model.SearchData.PageIndex, PageCount = Model.SearchData.PageCount, PageSize = Model.SearchData.PageSize, Parameters = Model.SearchData.Parameters})
    }
    </div>
    <div class="col-md-4 text-right">
    @if (isAdmin)
    {
        <a href="/board/create" class="btn btn-default">Write Article</a>
    }
    </div>

</div>






